home *** CD-ROM | disk | FTP | other *** search
- /* fscanf.c, from p.432 of Turbo C Bible */
- #include <stdio.h>
- main()
- {
- int i;
- FILE *infile;
- char token[80];
- /* Open the file. Note that we need two */
- /* '\' */
- if ((infile = fopen("c:\\autoexec.bat", "r")) == NULL)
- {
- perror("fopen failed");
- exit(1);
- }
- printf("First 10 blank separated strings in c:\\autoexec.bat:\n");
- for(i = 0; i < 10; i++)
- {
- if(fscanf(infile, " %s", token) == EOF)
- {
- printf("File ended!\n");
- break;
- }
- else
- {
- printf("Token %d = \"%s\"\n", i, token);
- }
- }
- }